package com.tank.demo.strategy.Impl;

import com.tank.demo.abstractFactory.BaseBullet;
import com.tank.demo.abstractFactory.BaseTank;
import com.tank.demo.facadeAndMediator.GameModel;
import com.tank.demo.strategy.FireStrategy;
import com.tank.demo.utils.ResourceMgr;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
public class DefaultFireStrategyImpl implements FireStrategy {
    @Override
    public void fire(BaseTank tank, BaseBullet bullet) {
        int bulletX = tank.getX(), bulletY = tank.getY();
        switch (tank.getDir()) {
            case UP:
                bulletX = tank.getX() + tank.width / 2 - bullet.width / 2;
                bulletY = tank.getY() - bullet.height;
                break;
            case DOWN:
                bulletX = tank.getX() + tank.width / 2 - bullet.width / 2;
                bulletY = tank.getY() + tank.height;
                break;
            case LEFT:
                bulletX = tank.getX() - ResourceMgr.bulletL.getWidth();
                bulletY = tank.getY() + tank.height / 2 - ResourceMgr.bulletL.getHeight() / 2;
                break;
            case RIGHT:
                bulletX = tank.getX() + tank.width;
                bulletY = tank.getY() + tank.height / 2 - ResourceMgr.bulletL.getHeight() / 2;
                break;
        }
        bullet.setX(bulletX);
        bullet.setY(bulletY);
        GameModel.getInstance().add(bullet);
    }
}
